package com.example.demo.model.enums;

import lombok.Getter;

/**
 * 项目类型枚举
 * 包含纵向课题和横向课题的分类体系
 */
@Getter
public enum ProjectTypeEnum {

    // ================= 纵向课题类型 =================
    NATIONAL_NATURAL_SCIENCE("NATIONAL", "国家自然科学基金", "纵向课题"),
    NATIONAL_SOCIAL_SCIENCE("NATIONAL", "国家社会科学基金", "纵向课题"),
    MINISTERIAL_LEVEL("MINISTERIAL", "部委级项目", "纵向课题"),
    PROVINCIAL_SCIENCE("PROVINCIAL", "省自然科学基金", "纵向课题"),
    PROVINCIAL_SOCIAL_SCIENCE("PROVINCIAL", "省社会科学基金", "纵向课题"),
    MUNICIPAL_LEVEL("MUNICIPAL", "市厅级项目", "纵向课题"),
    UNIVERSITY_LEVEL("UNIVERSITY", "校级项目", "纵向课题"),

    // ================= 横向课题类型 =================
    ENTERPRISE_COOPERATION("ENTERPRISE", "企业合作项目", "横向课题"),
    GOVERNMENT_CONSULTING("GOVERNMENT", "政府咨询项目", "横向课题"),
    TECHNICAL_DEVELOPMENT("TECHNICAL", "技术开发项目", "横向课题"),
    TECHNOLOGY_TRANSFER("TRANSFER", "技术转让项目", "横向课题"),
    TECHNICAL_SERVICE("SERVICE", "技术服务项目", "横向课题"),
    OTHER_COOPERATION("OTHER", "其他合作项目", "横向课题");

    /**
     * 类型编码（用于数据库存储）
     */
    private final String code;

    /**
     * 类型名称（用于显示）
     */
    private final String name;

    /**
     * 项目大类（纵向/横向）
     */
    private final String category;

    ProjectTypeEnum(String code, String name, String category) {
        this.code = code;
        this.name = name;
        this.category = category;
    }

    /**
     * 判断是否为纵向课题
     */
    public boolean isVertical() {
        return "纵向课题".equals(this.category);
    }

    /**
     * 判断是否为横向课题
     */
    public boolean isHorizontal() {
        return "横向课题".equals(this.category);
    }

    /**
     * 通过编码获取枚举
     */
    public static ProjectTypeEnum getByCode(String code) {
        for (ProjectTypeEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 通过名称获取枚举
     */
    public static ProjectTypeEnum getByName(String name) {
        for (ProjectTypeEnum value : values()) {
            if (value.getName().equals(name)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 获取所有纵向课题类型
     */
    public static ProjectTypeEnum[] getVerticalTypes() {
        return java.util.Arrays.stream(values())
                .filter(ProjectTypeEnum::isVertical)
                .toArray(ProjectTypeEnum[]::new);
    }

    /**
     * 获取所有横向课题类型
     */
    public static ProjectTypeEnum[] getHorizontalTypes() {
        return java.util.Arrays.stream(values())
                .filter(ProjectTypeEnum::isHorizontal)
                .toArray(ProjectTypeEnum[]::new);
    }
}